<template>
  <div :id="id" class="echarts" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: ['id', 'val', 'title'],
  name: '',
  data() {
    return {}
  },
  mounted() {
    this.init()
  },
  created() {},
  methods: {
    init() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById(this.id))
      // 绘制图表
      myChart.setOption({
        grid: {
          top: '0%',
          bottom: '10%'
        },
        tooltip: {
          formatter: '{a} <br/>{b} : {c}%'
        },
        series: [
          {
            type: 'gauge',
            radius: '80%',
            progress: {
              show: true,
              width: 8
            },
            axisLine: {
              lineStyle: {
                width: 8
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              length: 5,
              distance: 5,
              lineStyle: {
                width: 2,
                color: '#999'
              }
            },
            axisLabel: {
              show: false
            },
            anchor: {
              show: true,
              showAbove: true,
              size: 5,
              itemStyle: {
                borderWidth: 1
              }
            },
            title: {
              textStyle: {
                fontWeight: 'bolder'
              },
              show: true,
              fontSize: 15,
              color: '#fff',
              offsetCenter: [0, '90%']
            },
            detail: {
              valueAnimation: true,
              fontSize: 20,
              offsetCenter: [0, '40%'],
              color: '#fff',
              formatter: function (value) {
                return value + '%'
              }
            },
            data: [
              {
                value: this.val,
                name: this.title
              }
            ]
          }
        ]
      })
      // window.addEventListener('resize', function () {
      //     myChart.resize();
      // });
    }
  }
}
</script>
<style></style>